<template>
    <BPTable ref='tableRef' align='center' row-key='id' :columns='columns' :api='pageApi' :buttons='buttons'>
        <template #status='{record}'>
            <a-tag v-if='record.status' color='success'>{{$t('yes')}}</a-tag>
            <a-tag v-else>{{$t('no')}}</a-tag>
        </template>


        <template #$action='{record}'>
            <UpdateStatus v-if="!record.status" :id="record.id" v-model:status="record.status"></UpdateStatus>
        </template>
    </BPTable>
</template>

<script lang='ts' setup>
    import { pageApi, deleteApi } from '@/api/FeedbackRecord'
    import { message, Modal } from 'ant-design-vue'
    import { ref } from 'vue'
    import { useI18nStore } from '@/store/i18n'
    import { useResourceStore } from '@/store/resource'
import { parseTime } from "@/utils";
import UpdateStatus from './UpdateStatus.vue'


    

    const i18n = useI18nStore()
    const resourceStore = useResourceStore()

    const visible = ref(false)
    const formRef = ref()
    const dialogTitle = ref()

    const tableRef = ref()

    const currentRow = ref<any>()
    const currentCategory = ref()


    const buttons = ref<SearchButton[]>([])


    const columns = ref<Column[]>([
        {
            title : "联系方式",
            dataIndex : 'tel',
        },

        {
            title : '反馈内容',
            dataIndex : 'content',
            width : 600
        },

        {
            title : '是否已处理',
            dataIndex : 'status',
            inSearch : true,
            type : 'select',
            options : [{value : 0, label : '未处理'}, {value : 1, label : '已处理'}],
        },

        {
            title : '时间',
            dataIndex : 'createTime',
            customRender({ text }) {
                return parseTime(text)
            }
        },

        {
            title : i18n.t('operation'),
            dataIndex : '$action',
            align : 'center',

            $delete : async (row) => {
                const res = await deleteApi(row.id)
                if(res.success) {
                    message.success(i18n.t('deleteSuccess'))
                    tableRef.value.load()
                }else {
                    message.error(res.msg)
                }
            }
        }
    ])


    
</script>